<?php
class ControllerProductTopic extends FrontController {

	public function index() {
		$topic_id = G('topic_id', 0);
		M('catalog/topic');
		
		if ($topic_id) $topic = $this->model_catalog_topic->getTopic($topic_id);
		if (empty($topic)) $this->redirect(U('/'));

		$this->document->setTitle($topic['seo_title'] ? $topic['seo_title'] : $topic['title']);
		$this->document->setKeywords($topic['meta_keywords']);
		$this->document->setDescription($topic['meta_description']);
		
		$this->data['breadcrumbs'][] = array(
				'text'      => $topic['title'],
				'href'      => '',
				'separator' => $this->_['text_separator']
		);
		
		$this->data['topic'] = $topic;
		
		$topic_modules = $this->model_catalog_topic->getTopicModules($topic_id);
		$this->data['modules'] = array();
		
		foreach ($topic_modules as $module) {
			if ($module['type'] == 'banner') {
				$setting = array(
					'banner_id' => $module['data']['banner_id'],
					'template'  => $module['data']['template']		
				);
				$module = $this->getChild('module/banner', $setting);
			}
			elseif ($module['type'] == 'slideshow') {
				$setting = array(
						'banner_id' => $module['data']['banner_id'],
						'template'  => $module['data']['template']
				);
				$module = $this->getChild('module/slideshow', $setting);
			}
			elseif ($module['type'] == 'product') {
				$setting = array(
					'title' => $module['data']['title'][C('config_language_id')],
					'ref' => $module['data']['refid'],
					'template' => $module['data']['template']	
				);
				$module = $this->getChild('module/product_group', $setting);
			}
			elseif ($module['type'] == 'custom') {
				$setting = array(
					'description' => $module['data']		
				);
				$module = $this->getChild('module/custom', $setting);
			}
			if ($module) {
				$this->data['modules'][] = $module;
			}
		}
		
		$this->display('product/topic.tpl');
	}
}
?>